<?php

class Control_AvaAction extends Control_Action {

    public function setArgs($args = null) {
        if (null != $args) {
            $this->args = $args;
        }
        return $this;
    }

    public function setView($view) {
        if (null != $view) {
            $this->view = $view;
        }
        return $this;
    }

    public function run() {
        $t = Model_File::getSTime();
        if (Model_UserMapper::getCurrentUser($this->args['userId']) && isset($_SESSION['authUserId'])) {
            $this->args['photoId'] = Control_Validator::photoIdValid($this->args['photoId']);
            if ($this->args['photoId'] != false) {
                $id = $this->args['userId'];
                $res = (Model_UserMapper::setAva($this->args['userId'], $this->args['photoId']))?"?control=user&$id":"?control=photo&user=$id";
                $_SESSION['time'] = Model_File::getTime($t);
                $_SESSION['memory'] = memory_get_usage();
                header("location: http://petrovland.site50.net/$res");
            }
        } else {
            $_SESSION['time'] = Model_File::getTime($t);
            $_SESSION['memory'] = memory_get_usage();
            header('location: http://petrovland.site50.net');
        }
    }
        
}